package com.xtasz.itom.core;

/**
 * @author Marka
 * @date 2015/12/16
 * @Time 10:35
 */

import com.ibatis.sqlmap.client.SqlMapClient;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BaseDao {
    private SqlMapClientTemplate sqlMapClientTemplate = new SqlMapClientTemplate();

    protected List query(String paramString) {
        return this.sqlMapClientTemplate.queryForList(paramString);
    }

    protected List query(String paramString, Object paramObject) {
        return this.sqlMapClientTemplate.queryForList(paramString, paramObject);
    }

    protected List query(String paramString, Object paramObject, int paramInt1, int paramInt2) {
        return this.sqlMapClientTemplate.queryForList(paramString, paramObject, paramInt1, paramInt2);
    }

    protected Object querySingle(String paramString) {
        return this.sqlMapClientTemplate.queryForObject(paramString);
    }

    protected Object querySingle(String paramString, Object paramObject) {
        return this.sqlMapClientTemplate.queryForObject(paramString, paramObject);
    }

    protected int update(String paramString) {
        return this.sqlMapClientTemplate.update(paramString);
    }

    protected int update(String paramString, Object paramObject) {
        return this.sqlMapClientTemplate.update(paramString, paramObject);
    }

    protected int delete(String paramString) {
        return this.sqlMapClientTemplate.delete(paramString);
    }

    protected int delete(String paramString, Object paramObject) {
        return this.sqlMapClientTemplate.delete(paramString, paramObject);
    }

    protected Object insert(String paramString) {
        return this.sqlMapClientTemplate.insert(paramString);
    }

    protected Object insert(String paramString, Object paramObject) {
        return this.sqlMapClientTemplate.insert(paramString, paramObject);
    }

    public List<Map> queryBySql(String paramString) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("sql", paramString);
        return this.sqlMapClientTemplate.queryForList("selectBySql", localHashMap);
    }

    public final void setSqlMapClient(SqlMapClient paramSqlMapClient) {
        this.sqlMapClientTemplate.setSqlMapClient(paramSqlMapClient);
    }

    public String CreateTableName() {
        Calendar cal = Calendar.getInstance();//使用日历类
        int year = cal.get(Calendar.YEAR);//得到年
        int month = cal.get(Calendar.MONTH) + 1;//得到月，因为从0开始的，所以要加1
        int day = cal.get(Calendar.DAY_OF_MONTH);//得到天
        String datesuffix = "_" + year + (month >= 10 ? month : "0" + month) + (day >= 10 ? day : "0" + day);
        return datesuffix;
    }

    public String CreateTableNameY() {
        Calendar cal = Calendar.getInstance();//使用日历类
        cal.add(Calendar.DAY_OF_MONTH, -1);
        int year = cal.get(Calendar.YEAR);//得到年
        int month = cal.get(Calendar.MONTH) + 1;//得到月，因为从0开始的，所以要加1
        int day = cal.get(Calendar.DAY_OF_MONTH);//得到天
        String datesuffix = "_" + year + (month >= 10 ? month : "0" + month) + (day >= 10 ? day : "0" + day);
        return datesuffix;
    }
}